#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *thread_function(void *arg) {
    int *value = (int *)arg;
    printf("Hello from the new thread! Received value: %d\n", *value);
    pthread_exit(NULL);
}

int main() {
    pthread_t thread_id;
    int value = 42;

    if (pthread_create(&thread_id, NULL, thread_function, &value) != 0) {
        perror("pthread_create");
        exit(EXIT_FAILURE);
    }

    printf("Main thread: Created a new thread with ID %lu\n", thread_id);

    // 等待新线程结束
    pthread_join(thread_id, NULL);

    printf("Main thread: New thread has finished\n");

    return 0;
}
